package com.jmemoir.orm.mybatisplus.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jmemoir.base.common.dto.Result;
import com.jmemoir.orm.mybatisplus.entity.SysUser;
import com.jmemoir.orm.mybatisplus.service.SysUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户控制层
 *
 * @author Tellsea
 * @date 2023/8/4
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/sysUser")
public class SysUserController {

    private final SysUserService sysUserService;

    @GetMapping("/page")
    public Result<Page<SysUser>> page(SysUser entity) {
        return Result.success("操作成功", sysUserService.queryPage(entity));
    }

    @GetMapping("/list")
    public Result<List<SysUser>> list(SysUser entity) {
        return Result.success("操作成功", sysUserService.queryList(entity));
    }

    @GetMapping("/getById/{id}")
    public Result<SysUser> getById(@PathVariable Long id) {
        return Result.success("操作成功", sysUserService.getById(id));
    }

    @PostMapping("/add")
    public Result<String> add(@RequestBody SysUser sysUser) {
        sysUserService.save(sysUser);
        return Result.success("操作成功");
    }

    @PostMapping("/updateById")
    public Result<String> updateById(@RequestBody SysUser sysUser) {
        sysUserService.updateById(sysUser);
        return Result.success("操作成功");
    }

    @GetMapping("/removeById/{id}")
    public Result<String> removeById(@PathVariable("id") Long id) {
        sysUserService.removeById(id);
        return Result.success("操作成功");
    }

    @GetMapping("/removeByIds/{ids}")
    public Result<String> removeById(@PathVariable("ids") List<Long> ids) {
        sysUserService.removeByIds(ids);
        return Result.success("操作成功");
    }
}
